<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>添加宠物</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <form action="/addPet" enctype="multipart/form-data" method="post" style="width: 300px;margin: 10px auto;">
        <div class="form-group">
            <label for="name">昵称</label>
            <input type="text" name="name" class="form-control" id="name" placeholder="请输入昵称">
            <p id="msg"></p>
        </div>
        <div class="form-group">
            <label for="age">年龄</label>
            <input type="text" name="age" class="form-control" id="age" placeholder="请输入年龄">
        </div>
        <div class="form-group">
            <label for="color">颜色</label>
            <input type="text" name="color" class="form-control" id="color" placeholder="请输入颜色">
        </div>
        <div class="form-group">
            <label for="price">价格</label>
            <input type="number" name="price" class="form-control" id="price" placeholder="请输入价格">
        </div>
        <div class="form-group">
            <label >性别</label>
            <div class="radio">
                <label>
                    <input type="radio" name="gender" id="optionsRadios1" value="公" checked>公
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" name="gender" id="optionsRadios2" value="母">母
                </label>
            </div>
        </div>
        <div class="form-group">
            <label for="image">图片</label>
            <input type="file" name="pic" class="form-control" id="image">
        </div>
        <div class="form-group">
            <label for="typeId">类型</label>
            <select name="type_id" id="typeId">
                <option >请选择宠物类型</option>
                <c:forEach var="type" items="${petTypes}">
                    <option value="${type.id}">${type.name}</option>
                </c:forEach>
            </select>
        </div>
        <button type="submit" class="btn btn-default">保存</button>
    </form>
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <script>
        $("#name").blur(function () {
            $.get("/findPetByName?name="+$(this).val(),function (data) {
                if(data == "ok"){
                    $("#msg").text("该昵称可以使用").css("color","green");
                }else{
                    $("#msg").text("该昵称已经使用过").css("color","red");
                }
            })
        });
    </script>
</body>
</html>
